# dict = {"k1":"v1","k2":"v2","k3":"v3"}
# #循环遍历出字典子元素
# for key in dict.items() :
#     print(key)
# #单独遍历出key，value，可以使用for in
# for key,value in dict.items() :
#     print(key)
#     print(value)
# #或者直接使用for in 遍历出key和value
# for key in dict :
#     print(key)
#     print(dict[key])
# #循环遍历出key
# for keys in dict.keys() :
#     print(keys)
# #循环遍历出value
# for values in dict.values() :
#     print(values)
# #在字典中增加一个键值对，"k4":"v4"
# dict["k4"] = "v4"
# print(dict)






#小明去超市购买水果，账单如下，用字典表示，用水果名称做key，金额做value，创建一个字典
# info = {
#     "苹果":32.8,
#     "香蕉":22,
#     "葡萄":15.5
# }
# print(info["苹果"])

#小明，小刚去超市里购买水果小明购买了苹果，草莓，香蕉，小刚购买了葡萄，橘子，樱桃，请从下面的描述的字典中，计算每个人花费的金额，并写入到money字段里。以姓名做key，value仍然是字典
# friuts = {
#     "苹果":12.3,
#     "草莓":4.5,
#     "香蕉":6.3,
#     "葡萄":5.8,
#     "橘子":6.4,
#     "樱桃":15.8
# }
# info = {
#     "小明":{
#         "friuts":{"苹果":4,"草莓":13,"香蕉":10},
#         "money":27
#     },
#     "小刚":{
#         "fruits":{"葡萄":19,"橘子":12,"樱桃":30},
#         "money":61
#     }
# }





#编写一个函数，传入一个列表，并统计每个数字出现的次数。返回字典数据：{21:3,56:9,10:3}   （阿里一轮笔试题）
# def counter(a) :
#      b = {}
#      for i in a :
#          b[i] = a.count(i)
#      return b
# a = [21,21,21,56,56,56,56,56,56,56,56,56,10,10,10]
# # b = {}
# # for i in a :
# #     b[i] = a.count(i)
# print(counter(a))





#有以下公司员工信息，将数据转换为字典方式（姓名作为键，其他作为值,张三:{xxx:xxx,xx:xxx}）
# 姓名  年龄  性别  编号   任职公司   薪资   部门编号
# names = [
#     ["刘备","56","男","106","IBM", 500 ,"50"],
#     ["大乔","19","女","230","微软", 501 ,"60"],
#     ["小乔", "19", "女", "210", "Oracle", 600, "60"],
#     ["张飞", "45", "男", "230", "Tencent", 700 , "10"]
# ]
#方法一：用zip打包的方法将数据转换为字典方式
# a = []
# b = []
# for i in names :
#     a.append(i[0])
#     b.append(i[1:7])
# dict = dict(zip(a,b))
# print(dict)

#方法二：直接给键赋值
# a = {}
# for i in names :
#     a[i[0]] = i[1:7]
# print(a)













































